package com.lzb.browser.utils;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.SPUtils;
import com.google.gson.reflect.TypeToken;
import com.lzb.browser.bean.CollectBean;
import com.lzb.browser.bean.HomeBean;
import com.lzb.browser.bean.RecordBean;

import java.util.List;


public class AppSpUtils {
    private static final String SP_NAME = "appCollSp";
    private static final SPUtils sSpUtils = SPUtils.getInstance(SP_NAME);

    public static void saveHomeList(List<HomeBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_home_list, json);
    }

    public static List<HomeBean> getHomeList() {
        String json = sSpUtils.getString(Key.key_home_list);
        return GsonUtils.fromJson(json, new TypeToken<List<HomeBean>>() {
        }.getType());
    }

    public static void saveRecordList(List<RecordBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_record_list, json);
    }

    public static List<RecordBean> getRecordList() {
        String json = sSpUtils.getString(Key.key_record_list);
        return GsonUtils.fromJson(json, new TypeToken<List<RecordBean>>() {
        }.getType());
    }

    public static void saveCollectList(List<CollectBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_collect_list, json);
    }

    public static List<CollectBean> getCollectList() {
        String json = sSpUtils.getString(Key.key_collect_list);
        return GsonUtils.fromJson(json, new TypeToken<List<CollectBean>>() {
        }.getType());
    }

    interface Key {
        String key_home_list = "key_home_list";
        String key_record_list = "key_record_list";
        String key_collect_list = "key_collect_list";
    }
}